package com.yutel.gps.dao;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.druid.pool.DruidDataSourceFactory;

public class OracleDao {
	protected final Logger log = LoggerFactory.getLogger(getClass());
	private static DataSource ds;

	static {
		try {
			InputStream in = OracleDao.class.getClassLoader().getResourceAsStream("db.properties");
			Properties props = new Properties();
			props.load(in);
			ds = DruidDataSourceFactory.createDataSource(props);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	protected OracleDao() {
	}

	protected Connection getConnection() {
		try {
			return ds.getConnection();
		} catch (SQLException e) {
			log.error("get connect", e);
			return null;
		}
	}

	protected void close(Connection conn, PreparedStatement stmt, ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			log.error("close connect", e);
		}
	}

	public void destroy() {
	}
}
